<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${viewedAdvert.title}</title>
</head>
<body>

<table>
		<tr>
			<td>Title</td>
			<td>${viewedAdvert.title}</td>
		</tr>
		<tr>
			<td>Abstract Text</td>
			<td>${viewedAdvert.abstractText}</td>
		</tr>
		<tr>
			<td>Phone Number</td>
			<td>${viewedAdvert.phoneNumber}</td>
		</tr>
		<tr>
			<td>Address</td>
			<td>${viewedAdvert.address}</td>
		</tr>
		<tr>
			<td>Advertiser</td>
			<td><a href="${pageContext.request.contextPath}/advertisers/${viewedAdvert.advertiser.username}">${viewedAdvert.advertiser.username}</a></td>
		</tr>
		<tr>
			<td>Categories</td>
			<td>
				<c:forEach items="${viewedAdvert.categories}" var="currentCategory" varStatus="currentCategoryStatus">
					<a href="${pageContext.request.contextPath}/browse/${currentCategory.name}">${currentCategory.name}</a>
					<c:if test="${!currentCategoryStatus.last}">
						<c:out value=", "></c:out>
					</c:if>
				</c:forEach>
			</td>
		</tr>
</table>

<c:set var="applied">${ requestScope.agentApplied }</c:set>
<c:if test="${ not applied }">Apply for this advert:</c:if>
<form:form action="${pageContext.request.contextPath}/adverts/view/${viewedAdvert.id}/apply" modelAttribute="applyAdvertDto" method="POST">
	<form:input path="message" placeholder="Message to advertiser" disabled="${ applied }" required="required" />
	<input type="submit" value="Apply" <c:if test="${ applied }">disabled</c:if> >
</form:form>
<c:if test="${ applied }">You already applied for this advert.</c:if>

<br><br>
<a href="${pageContext.request.contextPath}/home"></a>

</body>
</html>